package com.scy;

import com.scy.demo.MyRannable;
import com.scy.demo.MyThread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo07 {
    //多线程
    // 多线程 的创建方式
    // 四种   继承Thread   实现Rannable   实现 Callable   线程池

    public static void main(String[] args) {
      /*  MyThread myThread1 = new MyThread();
        MyThread myThread2 = new MyThread();
        MyThread myThread3 = new MyThread();
        MyThread myThread4 = new MyThread();
        myThread1.setName("线程1");
        myThread2.setName("线程2");
        myThread3.setName("线程3");
        myThread4.setName("线程4");
        //开启线程
        myThread1.start();
        myThread2.start();
        myThread3.start();
        myThread4.start();*/

        /*MyRannable mr = new MyRannable();

        Thread t1 = new Thread(mr,"线程1");
        Thread t2 = new Thread(mr,"线程2");
        Thread t3 = new Thread(mr,"线程3");
        Thread t4 = new Thread(mr,"线程4");

        t1.start();
        t2.start();
        t3.start();
        t4.start();*/

        //创建线程池对象
        ExecutorService service = Executors.newFixedThreadPool(10);
        MyRannable mr = new MyRannable();
        service.submit(mr);
        service.submit(mr);
        service.submit(mr);
        service.submit(mr);


        service.shutdown();
    }
}
